/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

export function isEmpty(str) {
  return typeof str === 'undefined' || str == null || str === ''
}

export function validEmail(str) {
   return isEmpty(str) ? true : /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(str)
}

export function validMobile(str) {
  return isEmpty(str) ? true : /^[1][3,4,5,7,8][0-9]{9}$/.test(str)
}
